<template>
  <basic-container>
    <avue-crud v-if="tableOption"
               v-bind="bindVal"
               v-on="onEvent"
               v-model:page="page"
               v-model="startForm">
      <template #menu-btn="{row}">
        <el-dropdown-item v-if="row.procDefStatus===-1" text
                          divided
                          @click="btnUpdateDeployDefStatus(row,0)"
                          icon="el-icon-edit">激活
        </el-dropdown-item>
        <el-dropdown-item v-if="row.procDefStatus===0"
                          divided
                          @click="btnUpdateDeployDefStatus(row,-1)"
                          icon="el-icon-edit">挂起
        </el-dropdown-item>
        <el-dropdown-item divided
                          icon="el-icon-edit"
                          @click="actFormPropConfig(row)">表单属性配置
        </el-dropdown-item>
        <el-dropdown-item divided
                          icon="el-icon-edit"
                          @click="editFunConfig(row)">功能配置
        </el-dropdown-item>
      </template>
    </avue-crud>
    <edit-model-form-prop-dialog ref="editModelFormPropDialog"
                                 :get-tasks="actModelApi.getModelTasksByDeployId"
                                 :get-form-prop-config="actModelApi.getActFormPropConfigByDeployId"
                                 :save-form-prop-config="actModelApi.saveActFormPropConfigByDeployId"></edit-model-form-prop-dialog>
    <edit-deploy-proc-fun-conf-dialog ref="editDeployProcFunConfDialog"></edit-deploy-proc-fun-conf-dialog>

  </basic-container>
</template>

<script>
import {createDynamicMixin} from "@/mixins/startCrud";
import EditModelFormPropDialog from "@/views/start/activiti/model/editModelFormPropDialog.vue";
import actModelApi from "@/api/start/activiti/actModelApi";
import EditDeployProcFunConfDialog from "@/views/start/activiti/model/editDeployProcFunConfDialog.vue";

const mixinConfig = {
  name: "start/activiti/modelDeploymentHistory",
  apiPath: "start/activiti/actModel",
  list: "getModelDeployHistory",

}
export default {
  name: "deploymentHistory",
  computed: {
    actModelApi() {
      return actModelApi
    }
  },
  components: {EditDeployProcFunConfDialog, EditModelFormPropDialog},
  mixins: [createDynamicMixin(mixinConfig)],
  data() {
    return {
      modelKey: this.$route.params.modelKey,
    }
  },
  created() {

  },
  methods: {
    loadCrudOptionBefore(option) {

    },
    beforeLoadDataSource(search) {
      search.procDeployDefKey = this.modelKey
    },
    btnUpdateDeployDefStatus(row, status) {
      let label = "挂起"
      if (status === 0) {
        label = "激活"
      }
      this.$confirm("您确定要" + label + "流程" + row.defName + "（" + row.defVersion + "）", "系统提示").then(res => {
        return actModelApi.updateDeployDefStatus(row.id, status)
      }).then(res => {
        this.$message.success("操作成功")
        this.restLoadList();
      }).catch(err => {

      })
    },
    editFunConfig(row){
      this.$refs.editDeployProcFunConfDialog.show(row,`【${row.defName}】编辑-功能配置`)
    },
    actFormPropConfig(row) {
      this.$refs.editModelFormPropDialog.show(row, `已部署模型【${row.defName}】表单属性配置`)
    },
  }
}
</script>

<style scoped>

</style>